﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ClientAppViaWebService.StreamsLogicServiceRef;

namespace ClientAppViaWebService.Forms
{
    public partial class StreamEditForm : EducationalDivisionEditForm
    {
        private StreamsLogicService lService;
        private readonly Int32 ClassID = 8;


        public StreamEditForm()
        {
            InitializeComponent();
            lService = new StreamsLogicService();
            classTextBox.Text = ClassID.ToString();
        }

        public Double Lections
        {
            get { return Double.Parse(lectionsTextBox.Text); }
            set { lectionsTextBox.Text = value.ToString(); }
        }

        public Double Practic
        {
            get { return Double.Parse(practicTextBox.Text); }
            set { practicTextBox.Text = value.ToString(); }
        }

        protected override void SetFormProperties(Object _object)
        {
            Stream d = (_object as Stream);
            ID = d.ID;
            EXT_ID = d.EXT_ID;
            ParentId = d.PARENT_ID;
            Class = d.CLASS_ID;
            ObjName = d.NAME;
            BossName = d.BOSS_ID;
            DateCreated = d.DATE_CREATED;
            Description = d.DESCRIPTION;
            Practic = d.PRACTIC;
            Lections = d.LECTIONS;
        }

        protected override Object RetrieveFormProperties()
        {
            Stream str = new Stream();
            str.ID = ID;
            str.EXT_ID = EXT_ID;
            str.PARENT_ID = ParentId;
            str.CLASS_ID = Class;
            str.NAME = ObjName;
            str.DataBaseName = DataBaseName;
            str.BOSS_ID = BossName;
            str.DATE_CREATED = DateCreated;
            str.DESCRIPTION = Description;
            str.LECTIONS = Lections;
            str.PRACTIC = Practic;
            return str;
        }

        protected override void LoadEditFormData(int parentNodeID)
        {
            Stream p = lService.SelectStream_By_DataBase_And_Id(DataBaseName, parentNodeID);
            SetFormProperties(p);
        }

        protected override void UpdateEntity()
        {
            Stream obj = RetrieveFormProperties() as Stream;
            lService.UpdateStream(obj);
        }

        protected override void InsertEntity()
        {
            Stream obj = RetrieveFormProperties() as Stream;
            lService.InsertStream(obj);
        }
    }
}
